﻿#include "FITKSpectraAbstractAcceleration.h"
#include "FITKSpectraAlgorithm.h"

namespace Acoustics
{
    FITKSpectraAbstractAcceleration::FITKSpectraAbstractAcceleration()
    {
        //构造
    }

    FITKSpectraAbstractAcceleration::~FITKSpectraAbstractAcceleration()
    {
        //销毁
    }

    void FITKSpectraAbstractAcceleration::copy(FITKAcousticsAbstractSpectra * copyData)
    {
        FITKSpectraAbstractAcceleration* subCopyData = dynamic_cast<FITKSpectraAbstractAcceleration*>(copyData);
        if (copyData == nullptr || subCopyData == nullptr)return;
        FITKAcousticsAbstractSpectra::copy(copyData);
        _dBEnableState = subCopyData->getDBEnableState();
        _aWeightingEnableState = subCopyData->getAWeightingEnableState();
        _dBUserCoefficient = subCopyData->getDBDefaultCoefficient();
        _formCalcType = subCopyData->getFormCalcType();
    }


    void FITKSpectraAbstractAcceleration::setDBEnableState(bool enableState)
    {
        //设置dB计算的启用状态
        _dBEnableState = enableState;
    }

    bool FITKSpectraAbstractAcceleration::getDBEnableState()
    {
        //获取dB计算的启用状态
        return _dBEnableState;
    }

    double FITKSpectraAbstractAcceleration::getDBDefaultCoefficient()
    {
        //获取dB的默认系数 - 需要基类里实现
        return 0.0;
    }

    void FITKSpectraAbstractAcceleration::setDBUserCoefficient(double coeff)
    {
        _dBUserCoefficient = coeff;
    }

    double FITKSpectraAbstractAcceleration::getDBUserCoefficient()
    {
        if (_dBUserCoefficient < 0) return this->getDBDefaultCoefficient();
        return _dBUserCoefficient;
    }

    bool FITKSpectraAbstractAcceleration::isDBUserDefined()
    {
        if (_dBUserCoefficient > 0)return true;
        return false;
    }

    void FITKSpectraAbstractAcceleration::setAWeightingEnableState(bool enableState)
    {
        _aWeightingEnableState = enableState;
    }

    bool FITKSpectraAbstractAcceleration::getAWeightingEnableState()
    {
        return _aWeightingEnableState;
    }

    void FITKSpectraAbstractAcceleration::setFormCalcType(int type)
    {
        _formCalcType = type;
    }

    int FITKSpectraAbstractAcceleration::getFormCalcType()
    {
        return _formCalcType;
    }

    QList<SpectraValue> FITKSpectraAbstractAcceleration::getRealSpectraValue()
    {
        FITKSpectraAlgorithm* spectraAlg = this->getSpectraAlg();
        if (!spectraAlg) return QList<SpectraValue>();
        spectraAlg->setDBAlgConfig(_dBEnableState, _dBUserCoefficient);
        spectraAlg->setAWeighting(_aWeightingEnableState);
        spectraAlg->setCalcType(_formCalcType);
        if (!spectraAlg->startCalc(true)) return QList<SpectraValue>();
        return spectraAlg->getResults();
    }
}
